package com.shycloud.mido.task.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shycloud.mido.common.core.constant.CommonConstants;
import com.shycloud.mido.common.core.util.R;
import com.shycloud.mido.common.security.util.SecurityUtils;
import com.shycloud.mido.task.api.entity.SmMemberNotice;
import com.shycloud.mido.task.api.vo.NoticeVO;
import com.shycloud.mido.task.service.SmMemberNoticeService;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Api(tags = "通知公告")
@RestController
@AllArgsConstructor
@RequestMapping("/notice")
public class NoticeController {

	/** 通知公告业务 service */
	private SmMemberNoticeService noticeService;

	@GetMapping("getNotice")
	@ApiOperation("获取通知公告列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "type", value = "通知类型：0-系统消息 1-个人消息", dataType = "String")
	})
	public R<List<NoticeVO>> getNotice(String type) {

		if (SecurityUtils.getMember() == null) {
			return new R(CommonConstants.FAIL, "请先登录", false);
		}

		String memberId = SecurityUtils.getMember().getId();

		return new R(noticeService.getNotice(memberId, type));

	}

	@PostMapping("receiveReward")
	@ApiOperation(value = "系统通知领取奖励", notes = "传 id 和 orgId 即可")
	public R receiveReward(@RequestBody NoticeVO notice) {

		if (notice == null) {
			return new R(CommonConstants.FAIL, "未找到对应通知信息，请确认传入的 id 是否正确");
		}

		return new R(noticeService.receiveReward(notice.getOrgId(), notice.getId()));
	}

}
